<template>
  <div class="main_home_root">
    <div class="header_box">
      <img src="@/assets/logo.png">
      <div class="header_right">
        <span v-if="userInfo.usertype === 1">教师：{{ userInfo.loginname }}</span>
        <span v-if="userInfo.usertype === 2">学生：{{ userInfo.loginname }}</span>
        <span v-if="userInfo.usertype === 999">管理员：{{ userInfo.loginname }}</span>
        <span class="login_out" @click="loginOut">退出</span>
      </div>
    </div>
    <router-view/>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { useRouter } from 'vue-router';
import { useStore } from 'vuex';
export default defineComponent({
  setup() {
    const userInfoStr = localStorage.getItem("ts_userInfo");
    if (!userInfoStr) {
      return;
    }
    const userInfo = JSON.parse(userInfoStr);
    const router = useRouter();
    const store = useStore();
    const loginOut = () => {
      store.commit("clearUserInfo");
      router.push("/login");
    }
    return {
      userInfo,
      loginOut
    };
  }
});
</script>
<style lang="less" scoped>
.main_home_root {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: auto;
}
.header_box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 60px;
  font-size: 15px;
  background: #2d8cf0;
  color: #fff;
  > img {
    margin-left: 20px;
    width: 40px;
    height: 40px;
  }
  .header_right {
    margin-right: 20px;
    font-size: 20px;
    line-height: 60px;
    .login_out {
      margin-left: 20px;
      cursor: pointer;
    }
  }
}
</style>
